package com.itrip.itripbiz.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.itrip.common.DtoUtil;
import com.itrip.dto.Dto;
import com.itrip.entity.ItripHotelRoom;
import com.itrip.entity.ItripImage;
import com.itrip.entity.ItripLabelDic;
import com.itrip.service.ItripHotelRoomService;
import com.itrip.service.ItripImageService;
import com.itrip.service.ItripLabelDicService;
import com.itrip.vo.ItripImageVO;
import com.itrip.vo.hotelroom.ItripHotelRoomVO;
import com.itrip.vo.hotelroom.SearchHotelRoomVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("/biz/api")
public class HotelRommControler {

    @Resource
    private ItripHotelRoomService itripHotelRoomService;

    @Resource
    private ItripLabelDicService itripLabelDicService;

    @Resource
    private ItripImageService itripImageService;

    //查询酒店房型列表
    @PostMapping("/hotelroom/queryhotelroombyhotel")
    public Dto<ItripHotelRoomVO> ListirtipHotelRoom(@RequestBody SearchHotelRoomVO vo){
        QueryWrapper qw = new QueryWrapper();
        qw.select("hotelId","id","isBook","isCancel","isHavingBreakfast","isTimelyResponse",
                "payType","roomBedTypeId","roomPrice","roomTitle","satisfaction");

        //判断获取的条件是否为空
        if(vo.getHotelId() != null){
            qw.eq("hotelId",vo.getHotelId());
        } if(vo.getIsBook() != null){
            qw.eq("isBook",vo.getIsBook());
        } if(vo.getIsHavingBreakfast() != null){
            qw.eq("isHavingBreakfast",vo.getIsHavingBreakfast());
        } if(vo.getIsTimelyResponse() != null){
            qw.eq("isTimelyResponse",vo.getIsTimelyResponse());
        } if(vo.getRoomBedTypeId() != null){
            qw.eq("roomBedTypeId",vo.getRoomBedTypeId());
        } if(vo.getIsCancel() != null){
            qw.eq("isCancel",vo.getIsCancel());
        } if(vo.getPayType() != null || "".equals(vo.getPayType())){
            qw.eq("payType",vo.getPayType());
        }
        List<ItripHotelRoom> itripHotelRoom = itripHotelRoomService.list(qw);
        List list= new ArrayList();
        for (ItripHotelRoom hotelRoom : itripHotelRoom) {
            list.add(Arrays.asList(hotelRoom));
        }
        return DtoUtil.returnDataSuccess(list);
    }

    //查询所有床型
    @GetMapping("/hotelroom/queryhotelroombed")
    public Dto<ItripLabelDic> ListItripDicVo(){
        QueryWrapper qw = new QueryWrapper();
        qw.eq("parentId",1);
        List<ItripLabelDic> listDic = itripLabelDicService.list(qw);
        if(listDic == null){
            System.out.println("没有数据");
        }
        return DtoUtil.returnDataSuccess(listDic);
    }

    //查询酒店房型的图片
    @GetMapping("/hotelroom/getimg/{roomId}")
    public Dto<ItripImageVO>  QueryHotelPictures(@PathVariable("roomId") Long id){
        ItripImageVO itripImageVO = new ItripImageVO();
        QueryWrapper qw = new QueryWrapper();
        qw.eq("type",1);
        qw.eq("targetId",id);
        qw.select("imgUrl","position");
        List<ItripImage> itripImage = itripImageService.list(qw);
        return DtoUtil.returnDataSuccess(itripImage);
    }
}
